using UnityEngine;
using UnityEngine.UI;

namespace Share
{
    public class DashBoard : MonoBehaviour
    {
        [SerializeField]
        float m_fStart;
        [SerializeField]
        float m_fEnd;

        Image m_Image;

        void Start()
        {
            m_Image = GetComponent<Image>();
            // 初始设置为中间值
            SetValue(1, 1);
        }

        public void SetValue(float value1, float value2)
        {
            if (m_Image == null) return;
            if (value1 + value2 == 0)
            {
                SetValue(1, 1);
                return;
            }

            // 限制value在0~1之间
            float value = value1 / (value1 + value2);

            // 计算插值角度
            float angle = Mathf.Lerp(m_fStart, m_fEnd, value);

            // 应用旋转
            m_Image.transform.localEulerAngles = new Vector3(0, 0, angle);
        }
    }
}
